<template>
	<view>
		<view class="lis">
			<view class="dis_f aic jub" style=" padding: 30rpx 0;   border-bottom: 1px solid #efefef;">
				<view class="dis_f aic">
					<text style="font-size: 62rpx;
    color: #feb746;">¥</text>
					<input type="number" placeholder="请输入充值金额" v-model="price">
				</view>
			</view>
		</view>
	
		<view class="fs24 ml30" style="margin-top: 700rpx;">
			<text class="c9 ">点击立即充值，表示您已同意</text>
			<text class="cred" @click="jump">《充值协议》</text>
		</view>
		<view class="btnsub dis_f aic juc" @click="submit">
			立即充值
		</view>
	</view>
</template>
 
<script>
	export default {
		data() {
			return {
				list: [],
				isindex: 0,
				id: '',
				code: "",
				userinfo:"",
				price:""
			}
		},
		onLoad() {
			this.userinfo = uni.getStorageSync('userInfo') || ''
			this.postlist()
		},
		methods: {
			jump() {
				uni.navigateTo({
					url:'/pagesA/in_text/in_text?type='+3
				})
			},
			submit() {
				let that = this
				wx.login({
					success: async (res) => {
						that.code = res.code
						uni.setStorageSync("code", res.code);
						that.api.post('order/paytc', {
							price: that.price,
							code: that.code
						}).then(res => {
							console.log(res);
							if (res.code == 200) {
								uni.requestPayment({
									provider: 'wxpay', // 服务提提供商
									timeStamp: res.data.paymsg
									.timeStamp, // 时间戳 142326201502031615
									nonceStr: res.data.paymsg.nonceStr, // 随机字符串
									package: res.data.paymsg.package,
									signType: res.data.paymsg.signType, // 签名算法
									paySign: res.data.paymsg.paySign, // 签名
									success: function(res) {
										console.log('支付成功', res);
										uni.showToast({
											title: '充值成功',
											icon: "none"
										})
										setTimeout(function() {
											uni.navigateBack(1)
										}, 1000)
										// 业务逻辑。。。
									},
									fail: function(err) {
										console.log('支付失败', err);
									}
								});

							}


						})
					}
				})


			},
			postlist() {

				this.api.post('index/getCnslst').then(res => {
					console.log(res);
					if (res.code == 200) {

						this.list = res.data
						this.id = this.list[0].id
					}


				})
			},
			indexcli(index, item) {
				this.isindex = index
				this.id = item.id
			}
		}
	}
</script>

<style>
	.time {
		color: #a9a9a9;
		font-size: 24rpx;
		padding-top: 20rpx;
	}
	
	.tuig {
		font-size: 24rpx;
		color: red;
	}
	
	.tabzhon {
		position: relative;
		color: #feb746;
		font-size: 28rpx;
		font-weight: bold;
	}
	
	.tabzhon:before {
		content: '';
		position: absolute;
		bottom: -20rpx;
		width: 167rpx;
		height: 2px;
		background-color: #feb746;
		transform: translateX(-50%);
		left: 50%;
	}
	
	.tab {
		font-size: 28rpx;
	}
	
	.list {
		padding: 15rpx 20rpx;
		background: #fff;
		margin-bottom: 20rpx;
	}
	
	.list image {
		width: 100rpx;
		height: 100rpx;
	}
	
	.bottoms {
		background: #fff;
		padding: 30rpx;
	}
	
	input {
		width: 493rpx;
		margin-left: 15rpx
	}
	
	.guiz {
		border: 1px solid #feb746;
		border-radius: 60rpx;
		font-size: 22rpx;
		padding: 0 10rpx;
		color: #feb746;
	}
	
	.lis {
		background-color: #fff;
		padding: 25rpx 15rpx 0;
		margin: 0 25rpx 25rpx;
		border-radius: 12rpx;
	}
	.btnsub {
		width: 92%;
		margin-left: 30rpx;
		height: 75rpx;
		background: #feb746;
		border-radius: 15rpx;
		font-size: 30rpx;
		font-weight: normal;
		color: #FFFFFF;
		margin-top: 30rpx;
	}

	.mianx {

		background: #feb746 !important;
	}

	.mian {
		height: 120rpx;
		    background: #F3F3F3;
		    border-radius: 10rpx;
		    margin-right: 15rpx;
		    padding: 0 15rpx;
		    margin-bottom: 19rpx;
	}
</style>